class Node{
    constructor(value,next = null){
        this.value  = value
        this.next = next
    }
}

function ListNode(){
    const head = new Node(1)
    head.next = new Node(2)
    head.next.next = new Node(3)
    head.next.next.next = new Node(4)
    let p = head,ret =''
    while(p){
        ret += `${p.value}=>`
        p=p.next
    }
    ret +='null'
    console.log(ret)
}
ListNode(); 

/**
 * 双数组实现列表
 */
function ListNode2(){
    const data = [] //存放数据
    const next = [] //存放指针，存放下一个节点的下标

    //ind 节点后面插入节点 
    //P：节点在data数组中的下标,存在哪
    //val:节点的值
    function addNode(ind,p,val){
        data[p] = val
        next[p]  = next[ind]
        next[ind] = p;
    }

    let head = 3;
    data[3] = 'a'

    addNode(3,5,'b')
    addNode(5,7,'c')
    addNode(7,2,'d')
    addNode(2,1,'e')
    addNode(7,4,'f')

    let p = head,ret =''
    while(p){
        ret += `${data[p]}=>`
        p=next[p]
    }
    ret +='null'
    console.log(ret)
}

ListNode2();